<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<%@ taglib prefix="shiro"  uri="http://shiro.apache.org/tags"%>
<style>
	.scheduleBox{width:600px; height:auto}
</style>
<script>
$(function(){
	$('.date-picker').datepicker({
		autoclose: true,
		todayHighlight: true
	}).next().on(ace.click_event, function(){
		$(this).prev().focus();
	});
	
	var datatable = $("#productTable").DataTable({
		"language":{
			"url": "${pageContext.request.contextPath}/resources/admin/assets/de_DE.txt"
		},
		"dom": '<"top" >rt<"bottom" ifp><"clear">',
		"lengthMenu": [15, 3, 20,30],
		"pagingType": "full_numbers",
		"order":[[6,'desc']],
		"filter": false,
		"processing": true,
		"serverSide": true,
		"ajax": {
            "url": "${pageContext.request.contextPath}/product/product/productList.do",
            "type": "post"
        },
		 "columns": [
		        {"data":"id","sortable":false,"render":function(data,type,row){
		        	return '<input type="checkbox" class="ace" value="'+row.id+'"/> <span class="lbl"></span>'
		        },"class":"center","width":"10"},
				{ "data": "name","width":"100" },
                {"data" : "cname","width":"70",orderable:false},
                {"data": "filepath","width":"100px","render":function(data,type,row){
					return "<a href='#' onclick='viewImg(\""+data+"\")'>点击预览</a>";
                },"class":"center"},
                {"data": "title","width":"250"},
				{"data": "createUser","width":"70"},
                {"data":"createDate","render":function(data,type,row){
                    var d = new Date(data);
                    var month = d.getMonth()+1;
                    month = month < 10 ?"0"+month:month;
                    return d.getFullYear()+"-"+month+"-"+d.getDate();
                },"width:":"150"},
				{ "data": null,orderable: false,"render":function(data,type,row){
					return '<shiro:hasPermission name="product:product:edit">&nbsp;&nbsp;<a href="#" class="green" onclick="editProduct('+row.id+')"><i class="ace-icon fa fa-pencil"></i>编辑</a></shiro:hasPermission>'+ '<shiro:hasPermission name="product:product:del">&nbsp;&nbsp;<a href="#" class="red" onclick="delProduct('+row.id+')"><i class="ace-icon fa fa-trash-o "></i>删除</a></shiro:hasPermission>';
				}} 
	        ]
	});

	$('#refreshUser').click(function(){
		datatable.draw();
	})
	
	$('#doSearch').click(function(){
		datatable.draw();
	});
	
	$(document).on('click', 'th input:checkbox' , function(){
		var that = this;
		$(this).closest('table').find('tr > td:first-child input:checkbox')
		.each(function(){
			this.checked = that.checked;
			//$(this).closest('tr').toggleClass('selected');
		});
	});
});

//预览图片
function viewImg(imgFile) {
	var img = "${pageContext.request.contextPath}/"+imgFile;
	art.dialog({
		title:'图片预览',
		fixed:true,
		content:'<img width="600" src="'+img+'" />',
		background:'#ccc',
		top:'10%'
	});
}

function delProduct(id){
	var url = "${pageContext.request.contextPath}/product/product/productDel";
	$.post(url,{id:id},function(data){
		//var data = eval('(' + data + ')');
		if(data.success){
            art.dialog({content:data.msg,resize:true,time:2,icon:'succeed',ok:function(){this.close()}});
			$('#productTable').DataTable().draw() ;		//重新刷新数据表格
		}
	})
}


function editProduct(gid){
	var url = "${pageContext.request.contextPath}/product/product/editProduct";
	var dialog = art.dialog({
		id:'editProductDialog',
		lock:true,
		top:'40%'
	});
	$.post(url,{id:gid},function(data){
		dialog.content(data);
	});
}

</script>
<div class="breadcrumbs">
	<script type="text/javascript">
		try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
	</script>
	<ul class="breadcrumb">
		<li>
			<i class="ace-icon fa fa-home home-icon"></i>
			<a href="#">首页</a>
		</li>
		<li class="active">产品列表</li>
	</ul><!-- /.breadcrumb -->
	<div class="nav-search" id="nav-search">
		<form class="form-search">
			<span class="input-icon">
				<input type="text" placeholder="Search ..." class="nav-search-input" id="nav-search-input" autocomplete="off" />
				<i class="ace-icon fa fa-search nav-search-icon"></i>
			</span>
		</form>
	</div><!-- /.nav-search -->
</div>
<div class="page-content">
	<div class="row">
		<div class="col-sm-12">
			<div class="widget-box widget-color-dark">
				<div class="widget-header">
					<h5 class="widget-title">产品列表</h5>
					<div class="widget-toolbar">
						<shiro:hasPermission name="product:product:add">
							<button class="btn btn-xs btn-round btn-purple bigger" onclick="editProduct()">
								<i class="ace-icon fa fa-plus"></i>
								新增
							</button>
						</shiro:hasPermission>
						<button class="btn btn-xs btn-round btn-success bigger" id="refreshUser">
							<i class="ace-icon fa fa-refresh"></i>
							刷新
						</button>
					</div>
				</div>
				<div class="widget-body">
					<div class="widget-main padding-6">
						<table class="table row-border cell-border table-hover table-striped" id="productTable">
							<!-- <table class="table table-striped table-bordered table-hover" id="productTable"> -->
							<thead>
							<tr>
								<th class="center">
									<input type="checkbox" class="ace"/> <span class="lbl"></span>
								</th>
								<th>产品名称</th>
								<th>产品类别</th>
								<th>产品预览</th>
								<th>产品描述</th>
								<th>创建人</th>
								<th>创建时间</th>
								<th>操作</th>
							</tr>
							</thead>
						</table>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>